home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gsl.idb / usr / freeware / info / gsl-ref.info-7.z / gsl-ref.info-7
Text File  |  2000-10-09  |  50KB  |  1,177 lines

  1. This is gsl-ref.info, produced by Makeinfo version 3.12h from
  2. gsl-ref.texi.
  3.  
  4. INFO-DIR-SECTION Scientific software
  5. START-INFO-DIR-ENTRY
  6. * gsl-ref: (gsl-ref).                   GNU Scientific Library - Reference
  7. END-INFO-DIR-ENTRY
  8.  
  9.    This file documents the GNU Scientific Library.
  10.  
  11.    Copyright (C) 1996, 1997, 1998, 1999 The GSL Project.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided that
  19. the entire resulting derived work is distributed under the terms of a
  20. permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions, except that this permission notice may be stated in a
  25. translation approved by the Foundation.
  26.  
  27. 
  28. File: gsl-ref.info,  Node: Interpolation,  Next: Series Acceleration,  Prev: Roots of Polynomials,  Up: Top
  29.  
  30. Interpolation
  31. *************
  32.  
  33. Introduction
  34. ============
  35.  
  36.    This chapter describes functions for performing interpolation.  All
  37. the interpolation methods conform to a model which tries to factor out
  38. the various subtasks for creation, lookup and evaluation.  The state of
  39. an interpolation object is stored in a `gsl_interp_obj'; these are
  40. created by special purpose factories, one for each interpolation
  41. method.  State for searches is stored in a `gsl_interp_accel', which is
  42. a kind of iterator for interpolation lookups.
  43.  
  44.    The interpolation library provides five interpolation object
  45. factories:
  46.  
  47. `gsl_interp_factory_linear'
  48.      linear interpolation
  49.  
  50. `gsl_interp_factory_cspline_natural'
  51.      cubic spline with natural boundary conditions
  52.  
  53. `gsl_interp_factory_cspline_periodic'
  54.      cubic spline with periodic boundary conditions
  55.  
  56. `gsl_interp_factory_akima_natural'
  57.      Akima spline with natural boundary conditions
  58.  
  59. `gsl_interp_factory_akima_periodic'
  60.      Akima spline with periodic boundary conditions
  61.  
  62.    The interpolation object (`gsl_interp_obj') does not copy the data
  63. arrays but stores all static state computed from the data.  The "x"
  64. data array is always assumed to be strictly ordered; the behaviour for
  65. other arrangements is not defined.
  66.  
  67. Functions
  68. =========
  69.  
  70.  - Function: gsl_interp_accel * gsl_interp_accel_new (void)
  71.      Create an accelerator object, which is a kind of iterator for
  72.      interpolation lookups.  It tracks the state of lookups, thus
  73.      allowing for application of various acceleration strategies.
  74.  
  75.  - Function: size_t gsl_interp_accel_find (gsl_interp_accel * A, const
  76.           double x_array[], size_t SIZE, double X)
  77.      Perform a lookup action on a data array, using the given
  78.      accelerator.  This is how lookups are performed during evaluation
  79.      of an interpolation.  Returns an index such that `xarray[index] <=
  80.      x < xarray[index+1]'.
  81.  
  82.  - Function: int gsl_interp_eval_impl (const gsl_interp_obj * OBJ,
  83.           const double xa[], const double ya[], double X,
  84.           gsl_interp_accel * A, double * Y)
  85.  - Function: int gsl_interp_eval_e (const gsl_interp_obj * OBJ, const
  86.           double xa[], const double ya[], double X, gsl_interp_accel *
  87.           A, double * Y)
  88.  - Function: double gsl_interp_eval (const gsl_interp_obj * OBJ, const
  89.           double xa[], const double ya[], double X, gsl_interp_accel *
  90.           A)
  91.      Evaluate an interpolation at a given point, doing lookup with the
  92.      given accelerator state.
  93.  
  94.  - Function: int gsl_interp_eval_deriv_impl (const gsl_interp_obj *
  95.           OBJ, const double xa[], const double ya[], double X,
  96.           gsl_interp_accel * A, double * Y)
  97.  - Function: int gsl_interp_eval_deriv_e (const gsl_interp_obj * OBJ,
  98.           const double xa[], const double ya[], double X,
  99.           gsl_interp_accel * A, double * Y)
  100.  - Function: double gsl_interp_eval_deriv (const gsl_interp_obj * OBJ,
  101.           const double xa[], const double ya[], double X,
  102.           gsl_interp_accel * A)
  103.      Evaluate the derivative of an interpolation at a given point.
  104.  
  105.  - Function: void gsl_interp_obj_free (gsl_interp_obj * INTERP_OBJ)
  106.      Free an interpolation object.
  107.  
  108.  - Function: void gsl_interp_accel_free (gsl_interp_accel* A)
  109.      Free an accelerator object.
  110.  
  111. Examples
  112. ========
  113.  
  114. Creating and Using a Linear Interpolation
  115. -----------------------------------------
  116.  
  117.    The steps are to obtain a factory reference, create an interpolation
  118. object from given data, create an accelerator object (iterator), use
  119. the interpolation object and accelerator, and finally free resources.
  120.  
  121.        double x[64];
  122.        double y[64];
  123.        double x0;
  124.        double y0;
  125.        ...
  126.        gsl_interp_factory f = gsl_interp_factory_linear;
  127.        gsl_interp_obj * interp = f.create(x, y, 64);
  128.        gsl_interp_accel * a = gsl_interp_accel_new ();
  129.        ...
  130.        x0 = 5.7;
  131.        gsl_interp_eval_impl(interp, x, y, x0, a, &y0);
  132.        ...
  133.        gsl_interp_accel_free (a);
  134.        gsl_interp_obj_free (interp);
  135.  
  136. Creating and Using Other Interpolations
  137. ---------------------------------------
  138.  
  139.    To change the above code to use, say cubic splines with periodic
  140. boundary conditions, the only statement that would be changed is the
  141. one which obtains the reference to the factory.  We would do
  142.  
  143.        ...
  144.        /* gsl_interp_factory f = gsl_interp_factory_linear; */
  145.        gsl_interp_factory f = gsl_interp_factory_cspline_periodic
  146.        ...
  147.  
  148.    With this design, the interplation method can be changed
  149. dynamically, at runtime if desired, since the main block of code is
  150. unchanging and will work with any valid factory reference.
  151.  
  152. 
  153. File: gsl-ref.info,  Node: Series Acceleration,  Next: Random Number Generation,  Prev: Interpolation,  Up: Top
  154.  
  155. Series Acceleration
  156. *******************
  157.  
  158.    The functions described in this chapter accelerate the convergence
  159. of a series using the Levin u-transform.  This method takes a small
  160. number of terms from the start of a series and uses a systematic
  161. approximation to compute an extrapolated value and an estimate of its
  162. error.  The u-transform works for both convergent and divergent series,
  163. including asymptotic series.
  164.  
  165.    These functions are declared in the header file `gsl_sum.h'.
  166.  
  167. * Menu:
  168.  
  169. * Acceleration functions::
  170. * Example of accelerating a series::
  171. * Series Acceleration References::
  172.  
  173. 
  174. File: gsl-ref.info,  Node: Acceleration functions,  Next: Example of accelerating a series,  Up: Series Acceleration
  175.  
  176. Acceleration functions
  177. ======================
  178.  
  179.  - Function: int gsl_sum_levin_u_accel (const double * ARRAY, size_t
  180.           ARRAY_SIZE, double * Q_NUM, double * Q_DEN, double * DQ_NUM,
  181.           double * DQ_DEN, double * DSUM, double * SUM_ACCEL, double *
  182.           SUM_PLAIN, double * PRECISION)
  183.      This function takes the terms of a series in ARRAY of size
  184.      ARRAY_SIZE and computes the extrapolated limit of the series using
  185.      a Levin u-transform.  The extrapolated sum is stored in SUM_ACCEL,
  186.      with an estimate of the relative error stored in PRECISION.  The
  187.      actual term-by-term sum is returned in SUM_PLAIN.  Additional
  188.      working space must be provided in the arrays Q_NUM, Q_DEN, DSUM of
  189.      size ARRAY_SIZE elements each and in DQ_NUM, DQ_DEN of size
  190.      ARRAY_SIZE**2.  The algorithm estimates both truncation error and
  191.      round-off error to choose an optimal number of terms for the
  192.      extrapolation.
  193.  
  194. 
  195. File: gsl-ref.info,  Node: Example of accelerating a series,  Next: Series Acceleration References,  Prev: Acceleration functions,  Up: Series Acceleration
  196.  
  197. Example of accelerating a series
  198. ================================
  199.  
  200.    The following code calculates an estimate of \zeta(2) = \pi^2 / 6
  201. using the series,
  202.  
  203.      \zeta(2) = 1 + 1/2^2 + 1/3^2 + 1/4^2 + ...
  204.  
  205. After N terms the error in the sum is O(1/N), making direct summation
  206. of the series converge slowly.
  207.  
  208.      #include <stdio.h>
  209.      #include <gsl/gsl_math.h>
  210.      #include <gsl/gsl_sum.h>
  211.      
  212.      #define N 20
  213.      
  214.      int
  215.      main (void)
  216.      {
  217.        double t[N], qnum[N], qden[N], dsum[N], dqnum[N * N], dqden[N * N];
  218.        double sum_accel, sum_plain, prec;
  219.        double sum = 0;
  220.        size_t n_used ;
  221.        int n;
  222.      
  223.        const double zeta_2 = M_PI * M_PI / 6.0;
  224.      
  225.        /* terms for zeta(2) = \sum_{n=0}^{\infty} 1/n^2 */
  226.      
  227.        for (n = 0; n < N; n++)
  228.          {
  229.            double np1 = n + 1.0;
  230.            t[n] = 1.0 / (np1 * np1);
  231.            sum += t[n] ;
  232.          }
  233.      
  234.        gsl_sum_levin_u_accel (t, N, qnum, qden, dqnum, dqden, dsum,
  235.                               &sum_accel, &n_used, &sum_plain, &prec);
  236.      
  237.        printf("term-by-term sum = % .16f using %d terms\n", sum, N) ;
  238.        printf("term-by-term sum = % .16f using %d terms\n", sum_plain, n_used) ;
  239.        printf("exact value      = % .16f\n", zeta_2) ;
  240.        printf("accelerated sum  = % .16f using %d terms\n", sum_accel, n_used) ;
  241.        printf("estimated error  = % .16f\n", prec * sum_accel) ;
  242.        printf("actual error     = % .16f\n", sum_accel - zeta_2) ;
  243.      
  244.        return 0;
  245.      }
  246.  
  247. The ouput below shows that the Levin u-transform is able to obtain an
  248. estimate of the sum to 1 part in 10^10 using the first eleven terms of
  249. the series.  The error estimate returned by the function is also
  250. accurate, giving the correct number of significant digits.
  251.  
  252.      bash$ ./a.out
  253.      term-by-term sum =  1.5961632439130233 using 20 terms
  254.      term-by-term sum =  1.5759958390005426 using 13 terms
  255.      exact value      =  1.6449340668482264
  256.      accelerated sum  =  1.6449340668166479 using 13 terms
  257.      estimated error  =  0.0000000000508580
  258.      actual error     = -0.0000000000315785
  259.  
  260. Note that a direct summation of this series would require 10^10 terms
  261. to achieve the same precision as the accelerated sum does in 13 terms.
  262.  
  263. 
  264. File: gsl-ref.info,  Node: Series Acceleration References,  Prev: Example of accelerating a series,  Up: Series Acceleration
  265.  
  266. References and Further Reading
  267. ==============================
  268.  
  269. The algorithms used by these functions are described in the following
  270. papers,
  271.  
  272.      T. Fessler, W.F. Ford, D.A. Smith, HURRY: An acceleration
  273.      algorithm for scalar sequences and series `ACM Transactions on
  274.      Mathematical Software', 9(3):346-354, 1983.  and Algorithm 602
  275.      9(3):355-357, 1983.
  276.  
  277. The theory of the u-transform was presented by Levin,
  278.  
  279.      D. Levin, Development of Non-Linear Transformations for Improving
  280.      Convergence of Sequences, `Intern. J. Computer Math.' B3:371-388,
  281.      1973
  282.  
  283. 
  284. File: gsl-ref.info,  Node: Random Number Generation,  Next: Random Number Distributions,  Prev: Series Acceleration,  Up: Top
  285.  
  286. Random Number Generation
  287. ************************
  288.  
  289.    The GNU Scientific Library provides a large collection of random
  290. number generators which can be accessed through a uniform interface.
  291. Environment variables allow you to select different generators and
  292. seeds at runtime, so that you can easily switch between generators
  293. without needing to recompile your program.  Each instance of a
  294. generator keeps track of its own state, allowing the generators to be
  295. used in multi-threaded programs.  Additional functions are available
  296. for transforming uniform random numbers into samples from continuous or
  297. discrete probability distributions such as the Gaussian, log-normal or
  298. Poisson distributions.
  299.  
  300. * Menu:
  301.  
  302. * General comments on random numbers::
  303. * The Random Number Generator Interface::
  304. * Random number generator initialization::
  305. * Sampling from a random number generator::
  306. * Auxiliary random number generator functions::
  307. * Random number environment variables::
  308. * Saving and restoring random number generator state::
  309. * Random number generator algorithms::
  310. * Unix random number generators::
  311. * Numerical Recipes generators::
  312. * Other random number generators::
  313. * Random Number Generator Performance::
  314. * Random Number References and Further Reading::
  315. * Random Number Acknowledgements::
  316.  
  317. 
  318. File: gsl-ref.info,  Node: General comments on random numbers,  Next: The Random Number Generator Interface,  Up: Random Number Generation
  319.  
  320. General comments on random numbers
  321. ==================================
  322.  
  323.    In 1988, Park and Miller wrote a paper entitled "Random number
  324. generators: good ones are hard to find." [Commun. ACM, 31, 1192-1201].
  325. Fortunately, some excellent random number generators are available,
  326. though poor ones are still in common use.  You may be happy with the
  327. system-supplied random number generator on your computer, but you should
  328. be aware that as computers get faster, requirements on random number
  329. generators increase.  Nowadays, a simulation that calls a random number
  330. generator millions of times can often finish before you can make it down
  331. the hall to the coffee machine and back.
  332.  
  333.    A very nice review of random number generators was written by Pierre
  334. L'Ecuyer, as Chapter 4 of the book: Handbook on Simulation, Jerry Banks,
  335. ed. (Wiley, 1997).  The chapter is available in postscript from from
  336. L'Ecuyer's ftp site (see references).  Knuth's volume on Seminumerical
  337. Algorithms (originally published in 1968) devotes 170 pages to random
  338. number generators, and has recently been updated in its 3rd edition
  339. (1997).  It is brilliant, a classic.  If you don't own it, you should
  340. stop reading right now, run to the nearest bookstore, and buy it.
  341.  
  342.    A good random number generator will satisfy both theoretical and
  343. statistical properties.  Theoretical properties are often hard to obtain
  344. (they require real math!), but one prefers a random number generator
  345. with a long period, low serial correlation, and a tendency _not_ to
  346. "fall mainly on the planes."  Statistical tests are performed with
  347. numerical simulations.  Generally, a random number generator is used to
  348. estimate some quantity for which the theory of probability provides an
  349. exact answer.  Comparison to this exact answer provides a measure of
  350. "randomness".
  351.  
  352. 
  353. File: gsl-ref.info,  Node: The Random Number Generator Interface,  Next: Random number generator initialization,  Prev: General comments on random numbers,  Up: Random Number Generation
  354.  
  355. The Random Number Generator Interface
  356. =====================================
  357.  
  358.    It is important to remember that a random number generator is not a
  359. "real" function like sine or cosine.  Unlike real functions, successive
  360. calls to a random number generator yield different return values.  Of
  361. course that is just what you want for a random number generator, but to
  362. achieve this effect, the generator must keep track of some kind of
  363. "state" variable.  Sometimes this state is just an integer (sometimes
  364. just the value of the previously generated random number), but often it
  365. is more complicated than that and may involve a whole array of numbers,
  366. possibly with some indices thrown in.  To use the random number
  367. generators, you do not need to know the details of what comprises the
  368. state, and besides that varies from algorithm to algorithm.
  369.  
  370.    The random number generator library uses two special structs,
  371. `gsl_rng_type' which holds static information about each type of
  372. generator and `gsl_rng' which describes an instance of a generator
  373. created from a given `gsl_rng_type'.
  374.  
  375.    The functions described in this section are declared in the header
  376. file `gsl_rng.h'.
  377.  
  378. 
  379. File: gsl-ref.info,  Node: Random number generator initialization,  Next: Sampling from a random number generator,  Prev: The Random Number Generator Interface,  Up: Random Number Generation
  380.  
  381. Random number generator initialization
  382. ======================================
  383.  
  384.  - Random: gsl_rng * gsl_rng_alloc (gsl_rng_type * T)
  385.      This function returns a pointer to a newly-created instance of a
  386.      random number generator of type T.  For example, the following
  387.      code creates an instance of the Tausworthe generator,
  388.  
  389.           gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);
  390.  
  391.      If there is insufficient memory to create the generator then the
  392.      function returns a null pointer and the error handler is invoked
  393.      with an error code of `GSL_ENOMEM'.
  394.  
  395.      The generator is automatically initialized with the default seed,
  396.      `gsl_rng_default_seed'.  This is zero by default but can be changed
  397.      either directly or by using the environment variable
  398.      `GSL_RNG_SEED', *note Random number environment variables::..
  399.  
  400.      Some of the defined generator types are,
  401.  
  402.           gsl_rng_cmrg, gsl_rng_minstd, gsl_rng_mrg, gsl_rng_mt19937,
  403.           gsl_rng_r250, gsl_rng_ran0, gsl_rng_ran1, gsl_rng_ran2,
  404.           gsl_rng_ran3, gsl_rng_rand, gsl_rng_rand48,
  405.           gsl_rng_random_bsd, gsl_rng_random_glibc2,
  406.           gsl_rng_random_libc5, gsl_rng_randu, gsl_rng_ranf,
  407.           gsl_rng_ranlux, gsl_rng_ranlux389, gsl_rng_ranmar,
  408.           gsl_rng_slatec, gsl_rng_taus, gsl_rng_tds, gsl_rng_tt800,
  409.           gsl_rng_uni, gsl_rng_uni32, gsl_rng_vax, gsl_rng_zuf
  410.      The details of each generator are given later in this chapter.
  411.  
  412.  - Random: void gsl_rng_set (const gsl_rng * R, unsigned long int S)
  413.      This function initializes (or `seeds') the random number
  414.      generator.  If the generator is seeded with the same value of S on
  415.      two different runs, the same stream of random numbers will be
  416.      generated by successive calls to the routines below.  If different
  417.      values of S are supplied, then the generated streams of random
  418.      numbers should be completely different.  If the seed S is zero
  419.      then the standard seed from the original implementation is used
  420.      instead.  For example, the original Fortran source code for the
  421.      `ranlux' generator used a seed of 314159265, and so choosing S
  422.      equal to zero reproduces this when using `gsl_rng_ranlux'.
  423.  
  424.  - Random: void gsl_rng_free (gsl_rng * R)
  425.      This function frees all the memory associated with the generator R.
  426.  
  427. 
  428. File: gsl-ref.info,  Node: Sampling from a random number generator,  Next: Auxiliary random number generator functions,  Prev: Random number generator initialization,  Up: Random Number Generation
  429.  
  430. Sampling from a random number generator
  431. =======================================
  432.  
  433.    The following functions return uniformly distributed random numbers,
  434. either as integers or double precision floating point numbers.  To
  435. obtain non-uniform distributions *note Random Number Distributions::..
  436.  
  437.  - Random: unsigned long int gsl_rng_get (const gsl_rng * R)
  438.      This function returns a random integer from the generator R.  The
  439.      minimum and maximum values depend on the algorithm used, but all
  440.      integers in the range [MIN,MAX] are equally likely.  The values of
  441.      MIN and MAX can determined using the auxiliary functions
  442.      `gsl_rng_max (r)' and `gsl_rng_min (r)'.
  443.  
  444.  - Random: double gsl_rng_uniform (const gsl_rng * R)
  445.      This function returns a double precision floating point number
  446.      uniformly distributed in the range [0,1).  The range includes 0.0
  447.      but excludes 1.0.  The value is typically obtained by dividing the
  448.      result of `gsl_rng_get(r)' by `gsl_rng_max(r) + 1.0' in double
  449.      precision.  Some generators compute this ratio internally so that
  450.      they can provide floating point numbers with more than 32 bits of
  451.      randomness (the maximum number of bits that can be portably
  452.      represented in a single `unsigned long int').
  453.  
  454.  - Random: double gsl_rng_uniform_pos (const gsl_rng * R)
  455.      This function returns a positive double precision floating point
  456.      number uniformly distributed in the range (0,1), excluding both
  457.      0.0 and 1.0.  The number is obtained by sampling the generator
  458.      with the algorithm of `gsl_rng_uniform' until a non-zero value is
  459.      obtained.  You can use this function if you need to avoid a
  460.      singularity at 0.0.
  461.  
  462.  - Random: unsigned long int gsl_rng_uniform_int (const gsl_rng * R,
  463.           unsigned long int N)
  464.      This function returns a random integer from 0 to N-1 inclusive.
  465.      All integers in the range [0,N-1] are equally likely, regardless
  466.      of the generator used.  An offset correction is applied so that
  467.      zero is always returned with the correct probability, for any
  468.      minimum value of the underlying generator.
  469.  
  470.      If N is larger than the range of the generator then the function
  471.      calls the error handler with an error code of `GSL_EINVAL' and
  472.      returns zero.
  473.  
  474. 
  475. File: gsl-ref.info,  Node: Auxiliary random number generator functions,  Next: Random number environment variables,  Prev: Sampling from a random number generator,  Up: Random Number Generation
  476.  
  477. Auxiliary random number generator functions
  478. ===========================================
  479.  
  480.    The following functions provide information about an existing
  481. generator.  You should use them in preference to hard-coding the
  482. generator parameters into your own code.
  483.  
  484.  - Random: const char * gsl_rng_name (const gsl_rng * R)
  485.      This function returns a pointer to the name of the generator.  For
  486.      example,
  487.  
  488.           printf("r is a '%s' generator\n", gsl_rng_name (r)) ;
  489.  
  490.      would print something like `r is a 'taus' generator'
  491.  
  492.  - Random: unsigned long int gsl_rng_max (const gsl_rng * R)
  493.      `gsl_rng_max' returns the largest value that `gsl_rng_get' can
  494.      return.
  495.  
  496.  - Random: unsigned long int gsl_rng_min (const gsl_rng * R)
  497.      `gsl_rng_min' returns the smallest value that `gsl_rng_get' can
  498.      return.  Usually this value is zero.  There are some generators
  499.      with algorithms that cannot return zero, and for these generators
  500.      the minimum value is 1.
  501.  
  502.  - Random: void * gsl_rng_state (const gsl_rng * R)
  503.  - Random: size_t gsl_rng_size (const gsl_rng * R)
  504.      These function return a pointer to the state of generator R and
  505.      its size.  You can use this information to access the state
  506.      directly.  For example, the following code will write the state of
  507.      a generator to a stream,
  508.  
  509.           void * state = gsl_rng_state (r);
  510.           size_t n = gsl_rng_size (r);
  511.           fwrite (state, n, 1, stream);
  512.  
  513.  
  514. 
  515. File: gsl-ref.info,  Node: Random number environment variables,  Next: Saving and restoring random number generator state,  Prev: Auxiliary random number generator functions,  Up: Random Number Generation
  516.  
  517. Random number environment variables
  518. ===================================
  519.  
  520.    The library allows you to choose a default generator and seed from
  521. the environment variables `GSL_RNG_TYPE' and `GSL_RNG_SEED' and the
  522. function `gsl_rng_env_setup'.  This makes it easy try out different
  523. generators and seeds without having to recompile your program.
  524.  
  525.  - Function: const gsl_rng_type * gsl_rng_env_setup (void)
  526.      This function reads the environment variables `GSL_RNG_TYPE' and
  527.      `GSL_RNG_SEED' and uses their values to set the corresponding
  528.      library variables `gsl_rng_default' and `gsl_rng_default_seed'.
  529.      These global variables are defined as follows,
  530.  
  531.           extern const gsl_rng_type *gsl_rng_default
  532.           extern unsigned long int gsl_rng_default_seed
  533.  
  534.      The environment variable `GSL_RNG_TYPE' should be the name of a
  535.      generator, such as `taus' or `mt19937'.  The environment variable
  536.      `GSL_RNG_SEED' should contain the desired seed value.  It is
  537.      converted to an `unsigned long int' using the C library function
  538.      `strtoul'.
  539.  
  540.      If you don't specify a generator for `GSL_RNG_TYPE' then
  541.      `gsl_rng_mt19937' is used as the default.  The initial value of
  542.      `gsl_rng_default_seed' is zero.
  543.  
  544.  
  545. Here is a short program which shows how to create a global generator
  546. using the environment variables `GSL_RNG_TYPE' and `GSL_RNG_SEED',
  547.  
  548.      #include <stdio.h>
  549.      #include <gsl/gsl_rng.h>
  550.      
  551.      gsl_rng * r ;  /* global generator */
  552.      
  553.      int
  554.      main ()
  555.      {
  556.        gsl_rng_env_setup() ;
  557.      
  558.        r = gsl_rng_alloc (gsl_rng_default);
  559.      
  560.        printf("generator type: %s\n", gsl_rng_name (r));
  561.        printf("seed = %u\n", gsl_rng_default_seed);
  562.        printf("first value = %u\n", gsl_rng_get (r)) ;
  563.      }
  564.  
  565. Running the program without any environment variables uses the initial
  566. defaults, an `mt19937' generator with a seed of 0,
  567.  
  568.      bash$ ./a.out
  569.      generator type: mt19937
  570.      seed = 0
  571.      first value = 3510405877
  572.  
  573. By setting the two variables on the command line we can change the
  574. default generator and the seed,
  575.  
  576.      bash$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 ./a.out
  577.      GSL_RNG_TYPE=taus
  578.      GSL_RNG_SEED=123
  579.      generator type: taus
  580.      seed = 123
  581.      first value = 2720986350
  582.  
  583. 
  584. File: gsl-ref.info,  Node: Saving and restoring random number generator state,  Next: Random number generator algorithms,  Prev: Random number environment variables,  Up: Random Number Generation
  585.  
  586. Saving and restoring random number generator state
  587. ==================================================
  588.  
  589.    The above methods ignore the random number `state' which changes from
  590. call to call.  It is often useful to be able to save and restore the
  591. state.  To permit these practices, a few somewhat more advanced
  592. functions are supplied.  These include:
  593.  
  594.  - Random: int gsl_rng_memcpy (gsl_rng * DEST, const gsl_rng * SRC)
  595.      This function copies the random number generator SRC into the
  596.      pre-existing generator DEST, making DEST into an exact copy of
  597.      SRC.  The two generators must be of the same type.
  598.  
  599.  - Random: gsl_rng * gsl_rng_clone (const gsl_rng * R)
  600.      This function returns a pointer to a newly created generator which
  601.      is an exact copy of the generator R.
  602.  
  603.  - Random: void gsl_rng_print_state (const gsl_rng * R)
  604.      This function prints a hex-dump of the state of the generator R to
  605.      `stdout'.  At the moment its only use is for debugging.
  606.  
  607. 
  608. File: gsl-ref.info,  Node: Random number generator algorithms,  Next: Unix random number generators,  Prev: Saving and restoring random number generator state,  Up: Random Number Generation
  609.  
  610. Random number generator algorithms
  611. ==================================
  612.  
  613.    The functions described above make no reference to the actual
  614. algorithm used.  This is deliberate so that you can switch algorithms
  615. without having to change any of your application source code.  The
  616. library provides a large number of generators of different types,
  617. including simulation quality generators, generators provided for
  618. compatibility with other libraries and historical generators from the
  619. past.
  620.  
  621.    The following generators are recommended for use in simulation.  They
  622. have extremely long periods, low correlation and pass most statistical
  623. tests.
  624.  
  625.  - Generator: gsl_rng_mt19937
  626.      The MT19937 generator of Makoto Matsumoto and Takuji Nishimura is a
  627.      variant of the twisted generalized feedback shift-register
  628.      algorithm, and is known as the "Mersenne Twister" generator.  It
  629.      has a Mersenne prime period of 2^19937 - 1 (about 10^6000) and is
  630.      equi-distributed in 623 dimensions.  It has passed the DIEHARD
  631.      statistical tests.  It uses 624 words of state per generator and is
  632.      comparable in speed to the other generators.  The original
  633.      generator used a default seed of 4357 and choosing S equal to zero
  634.      in `gsl_rng_set' reproduces this.
  635.  
  636.      For more information see,
  637.           Makoto Matsumoto and Takuji Nishimura, "Mersenne Twister: A
  638.           623-dimensionally equidistributed uniform pseudorandom number
  639.           generator". `ACM Transactions on Modeling and Computer
  640.           Simulation', Vol. 8, No. 1 (Jan. 1998), Pages 3-30
  641.  
  642.  - Generator: gsl_rng_ranlxs0
  643.  - Generator: gsl_rng_ranlxs1
  644.  - Generator: gsl_rng_ranlxs2
  645.      The generator `ranlxs0' is a second-generation version of the
  646.      RANLUX algorithm of Lu"scher, which produces "luxury random
  647.      numbers".  This generator provides single precision output (24
  648.      bits) at three luxury levels `ranlxs0', `ranlxs1' and `ranlxs2'.
  649.      It uses double-precision floating point arithmetic internally and
  650.      can be significantly faster than the integer version of `ranlux',
  651.      particularly on 64-bit architectures.  The period of the generator
  652.      is about 10^171.  The algorithm has mathematically proven
  653.      properties and can provide truly decorrelated numbers at a known
  654.      level of randomness.
  655.  
  656.  - Generator: gsl_rng_ranlxd1
  657.  - Generator: gsl_rng_ranlxd2
  658.      These generators produce double precision output (48 bits) from the
  659.      RANLXS generator.  The library provides two luxury levels
  660.      `ranlxd1' and `ranlxd2'.
  661.  
  662.  - Generator: gsl_rng_ranlux
  663.  - Generator: gsl_rng_ranlux389
  664.      The `ranlux' generator is an implemenation of the original
  665.      algorithm developed by Lu"scher.  It uses a
  666.      lagged-fibonacci-with-skipping algorithm to produce "luxury random
  667.      numbers".  It is a 24-bit generator, originally designed for
  668.      single-precision IEEE floating point numbers.  This implementation
  669.      is based on integer arithmetic, while the second-generation
  670.      versions RANLXS and RANLXD described above provide floating-point
  671.      implementations which will be faster on many platforms.  The
  672.      period of the generator is about 10^171.  The algorithm has
  673.      mathematically proven properties and it can provide truly
  674.      decorrelated numbers at a known level of randomness.  The default
  675.      level of decorrelation recommended by Lu"scher is provided by
  676.      `gsl_rng_ranlux', while `gsl_rng_ranlux389' gives the highest
  677.      level of randomness, with all 24 bits decorrelated.  Both types of
  678.      generator use 24 words of state per generator.
  679.  
  680.      For more information see,
  681.           M. Lu"scher, "A portable high-quality random number generator
  682.           for lattice field theory calculations", `Computer Physics
  683.           Communications', 79 (1994) 100-110.
  684.  
  685.           F. James, "RANLUX: A Fortran implementation of the
  686.           high-quality pseudo-random number generator of Lu"scher",
  687.           `Computer Physics Communications', 79 (1994) 111-114
  688.  
  689.  - Generator: gsl_rng_cmrg
  690.      This is a combined multiple recursive generator by L'Ecuyer.  Its
  691.      sequence is,
  692.  
  693.           z_n = (x_n - y_n) mod m_1
  694.  
  695.      where the two underlying generators x_n and y_n are,
  696.  
  697.           x_n = (a_1 x_{n-1} + a_2 x_{n-2} + a_3 x_{n-3}) mod m_1
  698.           y_n = (b_1 y_{n-1} + b_2 y_{n-2} + b_3 y_{n-3}) mod m_2
  699.  
  700.      with coefficients a_1 = 0, a_2 = 63308, a_3 = -183326, b_1 = 86098,
  701.      b_2 = 0, b_3 = -539608, and moduli m_1 = 2^31 - 1 = 2147483647 and
  702.      m_2 = 2145483479.
  703.  
  704.      The period of this generator is 2^205 (about 10^61).  It uses 6
  705.      words of state per generator.  For more information see,
  706.  
  707.           P. L'Ecuyer, "Combined Multiple Recursive Random Number
  708.           Generators," `Operations Research', 44, 5 (1996), 816-822.
  709.  
  710.  - Generator: gsl_rng_mrg
  711.      This is a fifth-order multiple recursive generator by L'Ecuyer,
  712.      Blouin and Coutre.  Its sequence is,
  713.  
  714.           x_n = (a_1 x_{n-1} + a_5 x_{n-5}) mod m
  715.  
  716.      with a_1 = 107374182, a_2 = a_3 = a_4 = 0, a_5 = 104480 and m =
  717.      2^31 - 1.
  718.  
  719.      The period of this generator is about 10^46.  It uses 5 words of
  720.      state per generator.  More information can be found in the
  721.      following paper,
  722.           P. L'Ecuyer, F. Blouin, and R. Coutre, "A search for good
  723.           multiple recursive random number generators", `ACM
  724.           Transactions on Modeling and Computer Simulation' 3, 87-98
  725.           (1993).
  726.  
  727.  - Generator: gsl_rng_taus
  728.      This is a maximally equidistributed combined Tausworthe generator
  729.      by L'Ecuyer.  The sequence is,
  730.  
  731.           x_n = (s1_n ^^ s2_n ^^ s3_n)
  732.  
  733.      where,
  734.  
  735.           s1_{n+1} = (((s1_n&4294967294)<<12)^^(((s1_n<<13)^^s1_n)>>19))
  736.           s2_{n+1} = (((s2_n&4294967288)<< 4)^^(((s2_n<< 2)^^s2_n)>>25))
  737.           s3_{n+1} = (((s3_n&4294967280)<<17)^^(((s3_n<< 3)^^s3_n)>>11))
  738.  
  739.      computed modulo 2^32.  In the formulas above ^^ denotes
  740.      "exclusive-or".  Note that the algorithm relies on the properties
  741.      of 32-bit unsigned integers and has been implemented using a
  742.      bitmask of `0xFFFFFFFF' to make it work on 64 bit machines.
  743.  
  744.      The period of this generator is 2^88 (about 10^26).  It uses 3
  745.      words of state per generator.  For more information see,
  746.  
  747.           P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe
  748.           Generators", `Mathematics of Computation', 65, 213 (1996),
  749.           203-213.
  750.  
  751.  - Generator: gsl_rng_gfsr4
  752.      The `gfsr4' generator is like a lagged-fibonacci generator, and
  753.      produces each number as an `xor''d sum of four previous values.
  754.  
  755.           r_n = r_{n-A} ^^ r_{n-B} ^^ r_{n-C} ^^ r_{n-D}
  756.  
  757.      Ziff (ref below) notes that "it is now widely known" that two-tap
  758.      registers (such as R250, which is described below) have serious
  759.      flaws, the most obvious one being the three-point correlation that
  760.      comes from the defn of the generator.  Nice mathematical
  761.      properties can be derived for GFSR's, and numerics bears out the
  762.      claim that 4-tap GFSR's with appropriately chosen offsets are as
  763.      random as can be measured, using the author's test.
  764.  
  765.      This implementation uses the values suggested the the example on
  766.      p392 of Ziff's article: A=471, B=1586, C=6988, D=9689.
  767.  
  768.      If the offsets are appropriately chosen (such the one ones in this
  769.      implementation), then the sequence is said to be maximal.  I'm not
  770.      sure what that means, but I would guess that means all states are
  771.      part of the same cycle, which would mean that the period for this
  772.      generator is astronomical; it is (2^K)^D \approx 10^{93334} where
  773.      K=32 is the number of bits in the word, and D is the longest lag.
  774.      This would also mean that any one random number could easily be
  775.      zero; ie 0 <= r < 2^32.
  776.  
  777.      Ziff doesn't say so, but it seems to me that the bits are
  778.      completely independent here, so one could use this as an efficient
  779.      bit generator; each number supplying 32 random bits.
  780.  
  781.      For more information see,
  782.           Robert M. Ziff, "Four-tap shift-register-sequence
  783.           random-number generators", `Computers in Physics', 12(4),
  784.           Jul/Aug 1998, pp 385-392.
  785.  
  786. 
  787. File: gsl-ref.info,  Node: Unix random number generators,  Next: Numerical Recipes generators,  Prev: Random number generator algorithms,  Up: Random Number Generation
  788.  
  789. Unix random number generators
  790. =============================
  791.  
  792.    The standard Unix random number generators `rand', `random' and
  793. `rand48' are provided as part of GSL. Although these generators are
  794. widely available individually often they aren't all available on the
  795. same platform.  This makes it difficult to write portable code using
  796. them and so we have included the complete set of Unix generators in GSL
  797. for convenience.  Note that these generators don't produce high-quality
  798. randomness and aren't suitable for work requiring accurate statistics.
  799. However, if you won't be measuring statistical quantities and just want
  800. to introduce some variation into your program then these generators are
  801. quite acceptable.
  802.  
  803.  - Generator: gsl_rng_rand
  804.      This is the BSD `rand()' generator.  Its sequence is
  805.  
  806.           x_{n+1} = (a x_n + c) mod m
  807.  
  808.      with a = 1103515245, c = 12345 and m = 2^31.  The seed specifies
  809.      the initial value, x_1.  The period of this generator is 2^31, and
  810.      it uses 1 word of storage per generator.
  811.  
  812.  - Generator: gsl_rng_random_bsd
  813.  - Generator: gsl_rng_random_libc5
  814.  - Generator: gsl_rng_random_glibc2
  815.      These generators implement the `random()' family of functions, a
  816.      set of linear feedback shift register generators originally used
  817.      in BSD Unix.  There are several versions of `random()' in use
  818.      today: the original BSD version (e.g. on SunOS4), a libc5 version
  819.      (common on existing GNU/Linux systems) and a glibc2 version.  Each
  820.      version uses a different seeding procedure, and thus produces
  821.      different sequences.
  822.  
  823.      The original BSD routines accepted a variable length buffer for the
  824.      generator state, with longer buffers providing higher-quality
  825.      randomness.  The `random()' function implemented algorithms for
  826.      buffer lengths of 8, 32, 64, 128 and 256 bytes, and the algorithm
  827.      with the largest length that would fit into the user-supplied
  828.      buffer was used.  To support these algorithms additional
  829.      generators are available with the following names,
  830.  
  831.           gsl_rng_random8_bsd
  832.           gsl_rng_random32_bsd
  833.           gsl_rng_random64_bsd
  834.           gsl_rng_random128_bsd
  835.           gsl_rng_random256_bsd
  836.  
  837.      where the numeric suffix indicates the buffer length.  The
  838.      original BSD `random' function used a 128-byte default buffer and
  839.      so `gsl_rng_random_bsd' has been made equivalent to
  840.      `gsl_rng_random128_bsd'.  Corresponding versions of the `libc5'
  841.      and `glibc2' generators are also available, with the names
  842.      `gsl_rng_random8_libc5', `gsl_rng_random8_glibc2', etc.
  843.  
  844.  - Generator: gsl_rng_rand48
  845.      This is the Unix `rand48' generator.  Its sequence is
  846.  
  847.           x_{n+1} = (a x_n + c) mod m
  848.  
  849.      defined on 48-bit unsigned integers with a = 25214903917, c = 11
  850.      and m = 2^48.  The seed specifies the upper 32 bits of the initial
  851.      value, x_1, with the lower 16 bits set to `0x330E'.  The function
  852.      `gsl_rng_get' returns the upper 32 bits from each term of the
  853.      sequence.  This does not have a direct parallel in the original
  854.      `rand48' functions, but forcing the result to type `long int'
  855.      reproduces the output of `mrand48'.  The function
  856.      `gsl_rng_uniform' uses the full 48 bits of internal state to return
  857.      the double precision number x_n/m, which is equivalent to the
  858.      function `drand48'.  Note that some versions of the GNU C Library
  859.      contained a bug in `mrand48' function which caused it to produce
  860.      different results (only the lower 16-bits of the return value were
  861.      set).
  862.  
  863. 
  864. File: gsl-ref.info,  Node: Numerical Recipes generators,  Next: Other random number generators,  Prev: Unix random number generators,  Up: Random Number Generation
  865.  
  866. Numerical Recipes generators
  867. ============================
  868.  
  869.    The following generators are provided for compatibility with
  870. `Numerical Recipes'.  Note that the original Numerical Recipes
  871. functions used single precision while we use double precision.  This
  872. will lead to minor discrepancies, but only at the level of
  873. single-precision rounding error.  If necessary you can force the
  874. returned values to single precision by storing them in a `volatile
  875. float', which prevents the value being held in a register with double
  876. or extended precision.  Apart from this difference the underlying
  877. algorithms for the integer part of the generators are the same.
  878.  
  879.  - Generator: gsl_rng_ran0
  880.      Numerical recipes `ran0' implements Park and Miller's MINSTD
  881.      algorithm with a modified seeding procedure.
  882.  
  883.  - Generator: gsl_rng_ran1
  884.      Numerical recipes `ran1' implements Park and Miller's MINSTD
  885.      algorithm with a 32-element Bayes-Durham shuffle box.
  886.  
  887.  - Generator: gsl_rng_ran2
  888.      Numerical recipes `ran2' implements a L'Ecuyer combined recursive
  889.      generator with a 32-element Bayes-Durham shuffle-box.
  890.  
  891.  - Generator: gsl_rng_ran3
  892.      Numerical recipes `ran3' implements Knuth's portable subtractive
  893.      generator.
  894.  
  895. 
  896. File: gsl-ref.info,  Node: Other random number generators,  Next: Random Number Generator Performance,  Prev: Numerical Recipes generators,  Up: Random Number Generation
  897.  
  898. Other random number generators
  899. ==============================
  900.  
  901.    The generators in this section are provided for compatibility with
  902. existing libraries.  If you are converting an existing program to use
  903. GSL then you can select these generators to check your new
  904. implementation against the original one, using the same random number
  905. generator.  After verifying that your new program reproduces the
  906. original results you can then switch to a higher-quality generator.
  907.  
  908.    Note that most of the generators in this section are based on single
  909. linear congruence relations, which are the least sophisticated type of
  910. generator.  In particular, linear congruences have poor properties when
  911. used with a non-prime modulus, as several of these routines do (e.g.
  912. with a power of two modulus, 2^31 or 2^32).  This leads to periodicity
  913. in the least significant bits of each number, with only the higher bits
  914. having any randomness.  Thus if you want to produce a random bitstream
  915. it is best to avoid using the least significant bits.
  916.  
  917.    The following generator is provided for compatibility with the CRAY
  918. MATHLIB routine RANF. It produces double precision floating point
  919. numbers which should be identical to those from the original RANF.
  920.  
  921.  - Generator: gsl_rng_ranf
  922.      This is the CRAY random number generator `RANF'.  Its sequence is
  923.  
  924.           x_{n+1} = (a x_n) mod m
  925.  
  926.      defined on 48-bit unsigned integers with a = 44485709377909 and m
  927.      = 2^48.  The seed specifies the lower 32 bits of the initial value,
  928.      x_1, with the lowest bit set to prevent the seed taking an even
  929.      value.  The upper 16 bits of x_1 are set to 0. A consequence of
  930.      this procedure is that the pairs of seeds 2 and 3, 4 and 5, etc
  931.      produce the same sequences.
  932.  
  933.      There is a subtlety in the implementation of the seeding.  The
  934.      initial state is reversed through one step, by multiplying by the
  935.      modular inverse of a mod m.  This is done for compatibility with
  936.      the original CRAY implementation.
  937.  
  938.      Note that you can only seed the generator with integers up to
  939.      2^32, while the original CRAY implementation uses non-portable
  940.      wide integers which can cover all 2^48 states of the generator.
  941.  
  942.      The function `gsl_rng_get' returns the upper 32 bits from each term
  943.      of the sequence.  The function `gsl_rng_uniform' uses the full 48
  944.      bits to return the double precision number x_n/m.
  945.  
  946.      The period of this generator is 2^46.
  947.  
  948.  - Generator: gsl_rng_ranmar
  949.      This is the RANMAR lagged-fibonacci generator of Marsaglia, Zaman
  950.      and Tsang.  It is a 24-bit generator, originally designed for
  951.      single-precision IEEE floating point numbers.  It was included in
  952.      the CERNLIB high-energy physics library.
  953.  
  954.  - Generator: gsl_rng_r250
  955.      This is the shift-register generator of Kirkpatrick and Stoll.  The
  956.      sequence is
  957.  
  958.           x_n = x_{n-103} ^^ x_{n-250}
  959.  
  960.      where ^^ denote "exclusive-or", defined on 32-bit words.  The
  961.      period of this generator is about 2^250 and it uses 250 words of
  962.      state per generator.
  963.  
  964.      For more information see,
  965.           S. Kirkpatrick and E. Stoll, "A very fast shift-register
  966.           sequence random number generator", `Journal of Computational
  967.           Physics', 40, 517-526 (1981)
  968.  
  969.  - Generator: gsl_rng_tt800
  970.      This is an earlier version of the twisted generalized feedback
  971.      shift-register generator, and has been superseded by the
  972.      development of MT19937.  However, it is still an acceptable
  973.      generator in its own right.  It has a period of 2^800 and uses 33
  974.      words of storage per generator.
  975.  
  976.      For more information see,
  977.           Makoto Matsumoto and Yoshiharu Kurita, "Twisted GFSR
  978.           Generators II", `ACM Transactions on Modelling and Computer
  979.           Simulation', Vol. 4, No. 3, 1994, pages 254-266.
  980.  
  981.  - Generator: gsl_rng_vax
  982.      This is the VAX generator `MTH$RANDOM'.  Its sequence is,
  983.  
  984.           x_{n+1} = (a x_n + c) mod m
  985.  
  986.      with a = 69069, c = 1 and m = 2^32.  The seed specifies the
  987.      initial value, x_1.  The period of this generator is 2^32 and it
  988.      uses 1 word of storage per generator.
  989.  
  990.  - Generator: gsl_rng_transputer
  991.      This is the random number generator from the INMOS Transputer
  992.      Development system.  Its sequence is,
  993.  
  994.           x_{n+1} = (a x_n) mod m
  995.  
  996.      with a = 1664525 and m = 2^32.  The seed specifies the initial
  997.      value, x_1.
  998.  
  999.  - Generator: gsl_rng_randu
  1000.      This is the IBM `RANDU' generator.  Its sequence is
  1001.  
  1002.           x_{n+1} = (a x_n) mod m
  1003.  
  1004.      with a = 65539 and m = 2^31.  The seed specifies the initial value,
  1005.      x_1.  The period of this generator was only 2^29.  It has become a
  1006.      textbook example of a poor generator.
  1007.  
  1008.  - Generator: gsl_rng_minstd
  1009.      This is Park and Miller's "minimal standard" MINSTD generator, a
  1010.      simple linear congruence which takes care to avoid the major
  1011.      pitfalls of such algorithms.  Its sequence is,
  1012.  
  1013.           x_{n+1} = (a x_n) mod m
  1014.  
  1015.      with a = 16807 and m = 2^31 - 1 = 2147483647.  The seed specifies
  1016.      the initial value, x_1.  The period of this generator is about
  1017.      2^31.
  1018.  
  1019.      This generator is used in the IMSL Library (subroutine RNUN) and in
  1020.      MATLAB (the RAND function).  It is also sometimes known by the
  1021.      acronym "GGL" (I'm not sure what that stands for).
  1022.  
  1023.      For more information see,
  1024.           Park and Miller, "Random Number Generators: Good ones are
  1025.           hard to find", `Communications of the ACM', October 1988,
  1026.           Volume 31, No 10, pages 1192-1201.
  1027.  
  1028.  - Generator: gsl_rng_uni
  1029.  - Generator: gsl_rng_uni32
  1030.      This is a reimplementation of the 16-bit SLATEC random number
  1031.      generator RUNIF. A generalisation of the generator to 32 bits is
  1032.      provided by `gsl_rng_uni32'.  The original source code is
  1033.      available from NETLIB.
  1034.  
  1035.  - Generator: gsl_rng_slatec
  1036.      This is the SLATEC random number generator RAND. It is ancient.
  1037.      The original source code is available from NETLIB.
  1038.  
  1039.  - Generator: gsl_rng_zuf
  1040.      This is the ZUFALL lagged Fibonacci series generator of Peterson.
  1041.      Its sequence is,
  1042.  
  1043.           t = u_{n-273} + u_{n-607}
  1044.           u_n  = t - floor(t)
  1045.  
  1046.      The original source code is available from NETLIB.  For more
  1047.      information see,
  1048.           W. Petersen, "Lagged Fibonacci Random Number Generators for
  1049.           the NEC SX-3", `International Journal of High Speed
  1050.           Computing' (1994).
  1051.  
  1052. 
  1053. File: gsl-ref.info,  Node: Random Number Generator Performance,  Next: Random Number References and Further Reading,  Prev: Other random number generators,  Up: Random Number Generation
  1054.  
  1055. Random Number Generator Performance
  1056. ===================================
  1057.  
  1058.    The following table shows the relative performance of a selection the
  1059. available random number generators.  The simulation quality generators
  1060. which offer the best performance are `taus', `gfsr4' and `mt19937'.
  1061.  
  1062.        1754 k ints/sec,    870 k doubles/sec, taus
  1063.        1613 k ints/sec,    855 k doubles/sec, gfsr4
  1064.        1370 k ints/sec,    769 k doubles/sec, mt19937
  1065.         565 k ints/sec,    571 k doubles/sec, ranlxs0
  1066.         400 k ints/sec,    405 k doubles/sec, ranlxs1
  1067.         490 k ints/sec,    389 k doubles/sec, mrg
  1068.         407 k ints/sec,    297 k doubles/sec, ranlux
  1069.         243 k ints/sec,    254 k doubles/sec, ranlxd1
  1070.         251 k ints/sec,    253 k doubles/sec, ranlxs2
  1071.         238 k ints/sec,    215 k doubles/sec, cmrg
  1072.         247 k ints/sec,    198 k doubles/sec, ranlux389
  1073.         141 k ints/sec,    140 k doubles/sec, ranlxd2
  1074.      
  1075.        1852 k ints/sec,    935 k doubles/sec, ran3
  1076.         813 k ints/sec,    575 k doubles/sec, ran0
  1077.         787 k ints/sec,    476 k doubles/sec, ran1
  1078.         379 k ints/sec,    292 k doubles/sec, ran2
  1079.  
  1080. 
  1081. File: gsl-ref.info,  Node: Random Number References and Further Reading,  Next: Random Number Acknowledgements,  Prev: Random Number Generator Performance,  Up: Random Number Generation
  1082.  
  1083. References and Further Reading
  1084. ==============================
  1085.  
  1086.    The subject of random number generation and testing is reviewed
  1087. extensively in Knuth's `Seminumerical Algorithms'.
  1088.  
  1089.      Donald E. Knuth, `The Art of Computer Programming: Seminumerical
  1090.      Algorithms' (Vol 2, 3rd Ed, 1997), Addison-Wesley, ISBN 0201896842.
  1091.  
  1092. Further information is available in the review paper written by Pierre
  1093. L'Ecuyer, available at
  1094. <http://www.iro.umontreal.ca/~lecuyer/myftp/papers/handsim.ps>.
  1095.  
  1096.    On the World Wide Web, see the pLab home page
  1097. (<http://random.mat.sbg.ac.at/>) for a lot of information on the
  1098. state-of-the-art in random number generation, and for numerous links to
  1099. various "random" WWW sites.
  1100.  
  1101.    The source code for the DIEHARD random number generator tests is also
  1102. available online.
  1103.  
  1104.      `DIEHARD source code' G. Marsaglia
  1105.      <http://stat.fsu.edu/pub/diehard/>
  1106.  
  1107. 
  1108. File: gsl-ref.info,  Node: Random Number Acknowledgements,  Prev: Random Number References and Further Reading,  Up: Random Number Generation
  1109.  
  1110. Acknowledgements
  1111. ================
  1112.  
  1113. Thanks to Makoto Matsumoto, Takuji Nishimura and Yoshiharu Kurita for
  1114. making the source code to their generators (MT19937, MM&TN; TT800,
  1115. MM&YK) available under the GNU General Public License.  Thanks to Martin
  1116. Lu"scher for providing notes and source code for the RANLXS and RANLXD
  1117. generators.
  1118.  
  1119. 
  1120. File: gsl-ref.info,  Node: Random Number Distributions,  Next: Permutations,  Prev: Random Number Generation,  Up: Top
  1121.  
  1122. Random Number Distributions
  1123. ***************************
  1124.  
  1125.    Distributions of random numbers can be obtained from any of the
  1126. generators using the functions described in this section.  In the
  1127. simplest cases a non-uniform distribution can be obtained analytically
  1128. from the uniform distribution with an appropriate transformation.  This
  1129. method uses one call to the random number generator.
  1130.  
  1131.    More complicated distributions are created by the
  1132. "acceptance-rejection" method, which compares the desired distribution
  1133. against a distribution which is similar and known analytically.  This
  1134. usually requires several samples from the generator.
  1135.  
  1136.    The functions described in this section are declared in
  1137. `gsl_randist.h'.
  1138.  
  1139. * Menu:
  1140.  
  1141. * The Gaussian Distribution::
  1142. * The Gaussian Tail Distribution::
  1143. * The Bivariate Gaussian Distribution::
  1144. * The Exponential Distribution::
  1145. * The Laplace Distribution::
  1146. * The Exponential Power Distribution::
  1147. * The Cauchy Distribution::
  1148. * The Rayleigh Distribution::
  1149. * The Rayleigh Tail Distribution::
  1150. * The Symmetric Levy Distribution::
  1151. * The Gamma Distribution::
  1152. * The Flat (Uniform) Distribution::
  1153. * The Lognormal Distribution::
  1154. * The Chi-squared Distribution::
  1155. * The F-distribution::
  1156. * The t-distribution::
  1157. * The Beta Distribution::
  1158. * The Logistic Distribution::
  1159. * The Pareto Distribution::
  1160. * The Spherical Distribution (2D & 3D)::
  1161. * The Weibull Distribution::
  1162. * The Type-1 Gumbel Distribution::
  1163. * The Type-2 Gumbel Distribution::
  1164. * General Discrete Distributions::
  1165. * The Poisson Distribution::
  1166. * The Bernoulli Distribution::
  1167. * The Binomial Distribution::
  1168. * The Negative Binomial Distribution::
  1169. * The Pascal Distribution::
  1170. * The Geometric Distribution::
  1171. * The Hypergeometric Distribution::
  1172. * The Logarithmic Distribution::
  1173. * Shuffling and Sampling::
  1174. * Random Number Distribution Examples::
  1175. * Random Number Distribution References and Further Reading::
  1176.  
  1177.